using System;
using System.Text.RegularExpressions;

namespace GenericsFramework.BusinessRules
{
	public static class Extensions
	{
		public static bool Is<T>(this T selector, T value) where T : IComparable
		{
			return selector.CompareTo(value) == 0;
		}

		public static bool IsTrue(this bool selector)
		{
			return selector;
		}

		public static bool IsFalse(this bool selector)
		{
			return !selector;
		}

		public static bool IsGreaterThanOrEqualTo<T>(this T selector, T value) where T : IComparable
		{
			return selector.CompareTo(value) >= 0;
		}

		public static bool IsGreaterThan<T>(this T selector, T value) where T : IComparable
		{
			return selector.CompareTo(value) > 0;
		}

		public static bool IsLessThanOrEqualTo<T>(this T selector, T value) where T : IComparable
		{
			return selector.CompareTo(value) <= 0;
		}

		public static bool IsLessThan<T>(this T selector, T value) where T : IComparable
		{
			return selector.CompareTo(value) < 0;
		}

		public static bool IsNull<T>(this T selector)
		{
			return Equals(selector, null);
		}

		public static bool IsNotNull<T>(this T selector)
		{
			return !Equals(selector, null);
		}

		public static bool IsMatch(this object selector, string regex)
		{
			return selector.ToString().IsMatch(regex, RegexOptions.Compiled);
		}

		public static bool IsMatch(this object selector, string regex, RegexOptions options)
		{
			return Regex.IsMatch(selector.ToString(), regex, options | RegexOptions.Compiled);
		}
	}
}